package com.ludaxin.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import com.ludaxin.dao.UserDAO;
import com.ludaxin.model.Account;
import com.ludaxin.model.BaseModel;
import com.ludaxin.model.Page;
import com.ludaxin.model.User;
import com.ludaxin.model.vo.UserVo;
@Repository(value="userDAO")
public class UserDAOImpl implements UserDAO
{
    @Resource(name="sqlSession")
    private SqlSessionTemplate sqlSession;

    public List<User> getUsers(UserVo user)
    {
        return sqlSession.selectList("com.ludaxin.model.User.getUsers", user);
    }

    /**
     * 分页查询(mybatis拦截器)
     * @param String
     * @param BaseBean
     * @param String
     */   
    public List<? extends BaseModel> getAllAccountsPager(Account account, Page page) {
	List<? extends BaseModel> list=new ArrayList<BaseModel>();
    	list=sqlSession.selectList("com.ludaxin.model.User.getUserList",  page);
    	return list;
    }
    @Override
	public List<? extends BaseModel> getAllAccountsPager(Account account,
			Page page, String userId) {
	List<? extends BaseModel> list=new ArrayList<BaseModel>();
	page.setPageStr(userId);
    	list=sqlSession.selectList("com.ludaxin.model.User.getUserListByWhereStr",  page);
    	return list;
    }
    
    public int getAllAccountsCount() {
		
		int count=0;
		
		try {
			Integer countI=(Integer) sqlSession.selectOne("com.ludaxin.model.User.getAllAccountsCount");
			count=countI.intValue();
			
			System.out.println("============================== "+count+" ======================");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return count;
	}
    
    @Override
	public int getAllAccountsCount(String userId) {
		// TODO Auto-generated method stub
    	int count=0;
		
		try {
			Integer countI=(Integer) sqlSession.selectOne("com.ludaxin.model.User.getAllAccountsCountByWhereStr",userId);
			count=countI.intValue();
			
			System.out.println("=========================对方的法师===== "+count+" =======对方答复===============");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return count;
	}
    public SqlSessionTemplate getSqlSession()
    {
        return sqlSession;
    }

    public void setSqlSession(SqlSessionTemplate sqlSession)
    {
        this.sqlSession = sqlSession;
    }

	

	

    

    
}
